<script>
    layui.use('flow', function(){
        var flow = layui.flow;
        var $ = layui.jquery;
        //手动点击加载下一页
        flow.load({
            elem: '#centerlist' //流加载容器
            ,scrollElem: '#centerlist' //滚动条所在元素，一般不用填，此处只是演示需要。
            ,isAuto: false     //自动加载  为true的时候是自动加载
            ,isLazyimg: true   //图片懒加载
            ,end:'<div class="text-center"><button class="btn btn-simples">没有更多了</button></div>'
            ,done: function(page, next){ //加载下一页
                setTimeout(function(){
                    $.get(
                        "{:url('index/datalist')}",
                        {page:page},
                        function(d){
//                      console.log(d);
                            var lis = [];
                            layui.each(d.res, function(index, item){  //遍历后台传过来的数据
                                var txtCenters = item.description;
                                var recommended_text = item.recommended_text;
                                var topped_text = item.topped_text;
                                var system_message = item.system_message;
                                var hide_post_views = item.hide_post_views;
                                var hide_post_views_text = '';
                                var system_message_text = '';
                                var topped_text_new = '';
                                if(txtCenters.length > 40){
                                    txtCenters = txtCenters.substring(0,40) + '···';
                                }
                                if(item.create_time_text == 'New'){topped_text_new = '<span class="badge d-none d-md-inline-block post-new" style="margin-right:3px;">New</span>';}else if(item.recommended_text == '推荐'){topped_text_new = '<span class="badge d-none d-md-inline-block post-recommended" style="margin-right:3px;">推荐</span>';}else if(item.topped_text == '置顶'){topped_text_new = '<span class="badge d-none d-md-inline-block post-topped" style="margin-right:3px;">置顶</span>';}
                                if(system_message == 'on'){
                                    system_message_text = '<a class="c-sub-a" href="'+item.url+'#comments"><i class="layui-icon layui-icon-reply-fill mr-1"></i>'+item.newsMess+'<span class="t-sm d-none d-sm-inline-block">个评论</span></a>';
                                }else if(system_message == 'off'){
                                    system_message_text =='<a class="c-sub-a"></a>';
                                }
                                if(hide_post_views == 'on'){
                                    hide_post_views_text = '<i class="layui-icon layui-icon-eyes mr-1"></i>'+item.clicks+'<span class="t-sm d-none d-sm-inline-block">次阅读</span>'
                                }else if(hide_post_views == 'off'){
                                    hide_post_views_text = ''
                                }
                                var html =
							    '<!--文章ID - '+item.id+' -->'
                                +  '<article class="block card-plain post-item col-md-6 col-12 post-item-card">'
                                +  '<div class="p-block post-item-card-box">'
                                +  ''+topped_text_new+''
                                +  '<div class="thumbnail thumbnail-card">'
                                +  '<div class="thumbnail-inner">'
                                +  '<a class="t-sm" href="'+item.url+'">'
                                +  '<img title="'+item.title+'" alt="'+item.title+'" src="'+item.thumb+'" class="lazyload" data-src="'+item.thumb+'">'
                                +  '</a>'
                                +  '</div>'
                                +  '</div>'
                                +  '<div class="post-info">'
                                +  '<h2 class="info-title">'
                                +  '<a class="badge d-none d-md-inline-block '+item.ename+' ahfff" href="'+item.listurl+'">'+item.category_name+'</a>'
                                +  '<a class="a-link puock-text" title="" href="'+item.url+'"> '+item.title+'</a>'
                                +  '</h2>'
                                +  '<div class="info-meta c-sub">'
                                +  '<div class="text-2line">'
                                +  '<p>'+txtCenters+'</p>'
                                +  '</div>'
                                +  '</div>'
                                +  '<div class="info-footer w-100">'
                                +  '<div>'
                                +  '<span class="t-sm c-sub">'
                                +  ''+hide_post_views_text+''
                                +  ''+system_message_text+''
                                +  '</span>'
                                +  '</div>'
                                +  '<div>'
                                +  '<a class="c-sub-a t-sm ml-md-2 line-h-20 d-inline-block d-md-none" href="'+item.listurl+'"><i class="layui-icon layui-icon-note mr-1"></i>'+item.category_name+'</a>'
                                +  '<span class="t-sm ml-md-2 c-sub line-h-20 d-none d-md-inline-block">'+item.create_time_YMD_A+'</span>'
                                +  '</div>'
                                +  '</div>'
                                +  '</div>'
                                +  '</div>'
                                +  '</article>'
                                lis.push(html);
                            });
                            next(lis.join(''),page < d.total_page);  //拼接成字符串
                        }
                    );
                },500);
            }
        });
    });
</script>